package com.itheima.dao;

import com.itheima.domain.Teacher;

import java.util.ArrayList;

public class TeacherDao {
    ArrayList<Teacher> list = new ArrayList<>();

    public void addTeacher(Teacher tea) {
        list.add(tea);
    }

    public ArrayList<Teacher> findAllTeacher() {
        return list;
    }

    public void updateTeacher(Teacher tec) {
        for (int i = 0; i < list.size(); i++) {
            Teacher t = list.get(i);
            if (t.getId().equals(tec.getId())) {
                // 进行修改
                t.setName(tec.getName());
                t.setAge(tec.getAge());
                t.setBrithday(tec.getBrithday());
                return;
            }
        }
    }

    public void deleteTeacher(String id) {
        for (int i = 0; i < list.size(); i++) {
            if(id.equals(list.get(i).getId())){
                list.remove(i);
            }
        }
    }
}
